package cn.gson.springboot.controller;


import cn.gson.springboot.model.pojos.Customercare;
import cn.gson.springboot.model.service.CustomerCareService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CustomerCareController {
    @Autowired
    CustomerCareService customerCareService;

    @RequestMapping("/customercare-list")
    @ResponseBody
    public Map<String,Object> complainList(Integer page,Integer size, String search,Integer type) {
         Page<Object> obj = PageHelper.startPage(page, size);
        List<Customercare> customercares = customerCareService.selectAll(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",customercares);//返回查到的数据
        return map;
    }

    @RequestMapping("/customercare-deleteOne")
    @ResponseBody
    public void deleteOne() {
        customerCareService.deleteOne(2);
    }

    /*@RequestMapping("/customercare-selectOne")
    @ResponseBody
    public Customercare selectOne() {
        Customercare customercare = customerCareService.selectOne(2);
        return customercare;
    }*/

    @RequestMapping("/customercare-alter")
    @ResponseBody
    public void alter() {
        Customercare customercare = new Customercare();
        customercare.setCustomercareTheme("衣服有污渍");
        customerCareService.alter(1,customercare);

    }

    //@RequestMapping("/customercare-addCustomercare")
    @RequestMapping(value="/customercare-addCustomercare",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public void addCustomercare(@RequestBody(required = false) Customercare customercare) {
        System.out.println(customercare);
        customerCareService.addCustomercare(customercare);
    }
}